<template>
  <div ref="boxwrap" class="Capacity-Second">
    <div class="time-pick">
      <span>选择月份 </span>
      <el-date-picker
        v-model="month"
        type="month"
        placeholder="选择月份"
      />
    </div>
    <div class="main-content">
      <div class="box-wrap">
        <div class="title">累计生产产出</div>
        <div class="half-circle-wrap">
          <div class="half-circle orange">
            <span>1000</span>
            <span>A线</span>
          </div>
          <div class="half-circle blue">
            <span>2000</span>
            <span>B线</span>
          </div>
        </div>
        <div class="line-wrap">
          <line-chart id="output" height="100%" width="100%" />
        </div>
      </div>
      <div class="box-wrap">
        <div class="pie-wrap">
          <pie id="output-pie" height="100%" width="100%" />
        </div>
        <div class="output-percent">
          <div>
            <div><span>生产产出</span><span>/</span><span>故障产出</span></div>
            <div><span>100%</span><span>/</span><span>10%</span></div>
          </div>
          <div>
            <div><span>故障料号</span><span>/</span><span>故障工单号</span></div>
            <div><span>100%</span><span>/</span><span>10%</span></div>
          </div>
        </div>
      </div>
      <div class="box-wrap">
        <div class="title">累计故障产出</div>
        <div class="half-circle-wrap">
          <div class="half-circle green">
            <span>50000</span>
            <span>总产出</span>
          </div>
          <div class="half-circle purple">
            <span>50000</span>
            <span>预计总产出</span>
          </div>
        </div>
        <div class="line-wrap">
          <line-chart id="error-output" height="100%" width="100%" title="故障" :color="colors" />
        </div>
      </div>
      <div class="box-wrap">
        <div class="title">当天故障明细</div>
        <div ref="tablewrap" class="detail-table">
          <el-table :data="tableDataList" size="medium" border :height="tableHeight" :max-height="tableHeight">
            <el-table-column prop="partNum" label="料号" />
            <el-table-column prop="quantity" label="数量" />
            <el-table-column prop="time" label="时间" />
            <el-table-column prop="count" label="累积量" />
          </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import LineChart from './charts/capacity/Line'
import Pie from './charts/capacity/Pie'

export default {
  name: 'CapacitySecond',
  components: { LineChart, Pie },
  props: {
    width: {
      type: String,
      default: '800px'
    },
    height: {
      type: String,
      default: '600px'
    }
  },
  data() {
    return {
      month: '2021-08',
      colors: ['#00df5f', 'purple', 'orange'],
      partNumList: ['料号1', '料号2', '料号3'],
      tableHeight: 'auto',
      tableDataList: []
    }
  },
  mounted() {
    this.getDomStyle()
  },
  created() {
    this.getTableData()
  },
  methods: {
    getDomStyle() {
      const that = this
      const dom = this.$refs.boxwrap
      this.$erd.listenTo(dom, function(element) {
        that.tableHeight = (dom.clientHeight / 2 - 60)
      })
    },
    getTableData() {
      this.partNumList.forEach(item => {
        this.tableDataList.push({
          partNum: item,
          time: '',
          quantity: '',
          count: ''
        })
      })
    }
  }
}
</script>

<style lang="scss">
.el-date-editor.el-input, .el-date-editor.el-input__inner {
    width: 120px;
}

.Capacity-Second{
    width: 100%;
    height: 100%;

    .main-content{
      display: flex;
      flex-wrap: wrap;
      width: 100%;
      height: calc(100% - 46px);

      .box-wrap{
        width: 50%;
        height: 50%;
        &:nth-child(2){
          display: flex;
        }
        &:nth-child(2n){
          border-left: 1px solid #5967a4;
        }
        &:nth-last-child( -n + 2){
          border-top: 1px solid #5967a4;
        }

        .title{
          margin: 5px;
        }

        .half-circle-wrap{
          height: 80px;
          margin: 10px 0;
          display: flex;
          flex-wrap: nowrap;
          justify-content: space-evenly;

          .half-circle {
            /* 半圆 */
            width: 160px;
            height: 80px;
            border: 15px solid #5967a4;
            border-bottom: 0;
            border-radius: 80px 80px 0 0;
            text-align: center;
            /* 文字底部对齐 */
            display: inline-flex;
            flex-direction: column;
            justify-content: flex-end;

            &.orange{
              border-color:orange;
            }
            &.blue{
              border-color: deepskyblue;
            }
            &.green{
              border-color: #00df5f;
            }
            &.purple{
               border-color: purple;
            }

            span{
              display: block;
            }
          }
        }

        .line-wrap {
          height: calc(100% - 36px - 100px);
        }

        .detail-table {
          width: 100%;
          height: calc(100% - 30px);
          padding: 0 10px;
        }

        .pie-wrap{
          width: 50%;
          height: 100%;
        }

        .output-percent{
          width: 50%;
          height: 100%;
          margin-top: 20px;

            span{
              display: inline-block;
              width: 33%;
              text-align: center;
            }

          >div{
            padding: 10px;
            > div:not(:first-child){
                border: 1px solid #5967a4;
                margin-top: 10px;
                padding: 10px;
            }
          }
        }
      }
    }
}
</style>
